﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HJ_SQL_ToTable
{
    /// <summary>
    ///     文件读取工具，将内容读取到StringBuilder中
    /// </summary>
    public class ReadUtil
    {
        public static StringBuilder ReadContent(string path)
        {
            StringBuilder sbContent = new StringBuilder();
            FileStream fs = null;
            StreamReader sr = null;
            try
            {
                fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                sr = new StreamReader(fs, System.Text.Encoding.UTF8);

                sbContent.Append(sr.ReadToEnd());
            }
            catch (Exception ex)
            {
                sbContent.Clear();
            }
            finally {
                if (sr != null)
                    sr.Close();
                if (fs != null)
                    fs.Close();
            }

            return sbContent;
        }
    }
}
